import axios from "axios";
let baseUrl = "http://localhost:8081/"

// 登录
export const loginShop = (type, username, pwd) => {
    return axios.request({
        method: type,
        url: baseUrl + "user?username=" + username+"&passsword="+pwd
    })
}
// 获取用户信息
export const handUserInfo = (type, id) => {
    return axios.request({
        method: type,
        url: baseUrl + "user?id=" + id
    })
}
// 页面加载查询所有商品
export const handGoods = (type, address) => {
    return axios.request({
        method: type,
        url: baseUrl + address
    })
}
// 根据用户输入查询商品
export const seach = (type, goodsName) => {
    return axios.request({
        method: type,
        url: baseUrl + "goodsList?name_like=" + goodsName
    })
}
// 根据用户输入查询商品
export const seachClassify = (type, classfiy) => {
    return axios.request({
        method: type,
        url: baseUrl + "goodsList?classify_like=" + classfiy
    })
}
// 注册用户
export const register = (type, data) => {
    return axios.request({
        headers: {
            "Content-type": "application/json"
        },
        method: type,
        url: baseUrl + "user/",
        data: data
    })
}
// 修改头像、修改用户信息、
export const upload = (type, id, data) => {
    return axios.request({
        headers: {
            "Content-type": "application/json"
        },
        method: type,
        url: baseUrl + "user/" + id,
        data: data
    })
}
// 提交订单
export const addOrder = (type, data) => {
    return axios.request({
        headers: {
            "Content-type": "application/json"
        },
        method: type,
        url: baseUrl + "userOrder/",
        data: data
    })
}

// 向购物车添加数据
export const addCart = (type, data) => {
    return axios.request({
        headers: {
            "Content-type": "application/json"
        },
        method: type,
        url: baseUrl + "UserCart/",
        data: data
    })
}
// 更新购物车数据
export const patchCart = (type,id,data) => {
    return axios.request({
        headers: {
            "Content-type": "application/json"
        },
        method: type,
        url: baseUrl + "UserCart/" + id,
        data: data
    })
}
// 向购物车添加数据时查询购物车有无该数据数据
export const seachCart = (type, userId, goodsId) => {
    return axios.request({
        method: type,
        url: baseUrl + "UserCart?userId=" + userId + "&goodsId=" + goodsId,
    })
}
// 查询登录用户购物车数据
export const seachUserCart = (type, userId, goodsId) => {
    return axios.request({
        method: type,
        url: baseUrl + "UserCart?userId=" + userId 
    })
}
// 删除购物车数据
export const delCart=(type,goodsId)=>{
    return axios.request({
        method: type,
        url: baseUrl + "UserCart/" +goodsId
    })
}

// 订单分页查询
export const handOrder=(type,page,limit,userId)=>{
    return axios.request({
        method: type,
        url: baseUrl + "userOrder?_page="+page+"&_limit="+limit+"&userId_like=" + userId
    })
}

// 创建实例
// const http =  axios.create({})
// 拦截器
// 拦截发送
// http.interceptors.request.use(
// 	function (config) {
// 		// 在发送请求之前做些什么
// 		return config
// 	},
// 	function (error) {
// 		// 对请求错误做些什么
// 		console.log(error)
// 		return Promise.reject(error)
// 	}
// )

// 拦截返回
// http.interceptors.response.use((res)=>{
// console.log(res);
// },
// (error)=>{
// console.log(error);
// })
// export default http //默认导出 (只能有一个默认导出)
// export {http}; //非默认导出 （可以导出多个）
